﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InfoSource.Models.objects;
using InfoSource.Data;

namespace InfoSource.Models.Views
{
    public class AppointmentReminders_SendIndividualAppointmentReminderViewModel
    {
        public List<EmailTemplate> EmailTemplates { get; set; }

		public AppointmentReminders_SendIndividualAppointmentReminderViewModel()
        {
            EmailTemplates = AppointmentRemindersRequests.GetAppointmentReminderEmailTemplates();
        }

		/*--------------------------------------------------------------------*/
		public string PreviewTemplate(int contractID, int applianceID, int templateID)
		{
			Contract contract = AppointmentRemindersRequests.GetSingleContract(contractID);
			Appliance appliance = AppointmentRemindersRequests.GetSingleAppliance(applianceID);
			t_EmailTemplates template = AppointmentRemindersRequests.GetSingleTemplate(templateID);

			string body = HttpUtility.HtmlDecode(template.TemplateBody);

			body = body.Replace("{full name}", (contract.First_Name ?? "").Trim() + " " + (contract.Last_Name ?? "").Trim());
			body = body.Replace("{last name}", (contract.Last_Name ?? "").Trim());
			body = body.Replace("{Service Street Address}", (contract.Serv_House_No ?? "").Trim() + " " + (contract.Serv_addr ?? "").Trim());
			body = body.Replace("{Service City}", (contract.Serv_City ?? "").Trim());
			body = body.Replace("{Service State}", (contract.Serv_State ?? "").Trim());
			body = body.Replace("{Service Zip}", (contract.Serv_Zip ?? "").Trim());
			body = body.Replace("{Mailing Street Address}", (contract.Mail_House_No ?? "").Trim() + " " + (contract.Mail_Addr ?? "").Trim());
			body = body.Replace("{Mailing City}", (contract.Mail_City ?? "").Trim());
			body = body.Replace("{Mailing State}", (contract.Mail_State ?? "").Trim());
			body = body.Replace("{Mailing Zip}", (contract.Mail_Zip ?? "").Trim());
			body = body.Replace("{Appliance}", (appliance.Description ?? "").Trim());

			return body;
		}


    }
}